<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>S110_nRF51822/Board/nrf6310_nrf2752/ble/ble_app_hrs/main.c Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css" />
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="alias.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="alias.js"></script>

<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>


<script type="text/javascript">
  jQuery(document).ready(function () {
    if(gref){ // Number all _img and _table classes
      gref();
    }
  });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->

<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">nRF51822 BLE SDK
   
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('nrf6310__nrf2752_2ble_2ble__app__hrs_2main_8c.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">S110_nRF51822/Board/nrf6310_nrf2752/ble/ble_app_hrs/main.c</div>  </div>
</div>
<div class="contents">
<a href="nrf6310__nrf2752_2ble_2ble__app__hrs_2main_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.</span>
<a name="l00002"></a>00002 <span class="comment"> *</span>
<a name="l00003"></a>00003 <span class="comment"> * The information contained herein is confidential property of Nordic</span>
<a name="l00004"></a>00004 <span class="comment"> * Semiconductor ASA.Terms and conditions of usage are described in detail</span>
<a name="l00005"></a>00005 <span class="comment"> * in NORDIC SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.</span>
<a name="l00006"></a>00006 <span class="comment"> *</span>
<a name="l00007"></a>00007 <span class="comment"> * Licensees are granted free, non-transferable use of the information. NO</span>
<a name="l00008"></a>00008 <span class="comment"> * WARRANTY of ANY KIND is provided. This heading must NOT be removed from</span>
<a name="l00009"></a>00009 <span class="comment"> * the file.</span>
<a name="l00010"></a>00010 <span class="comment"> *</span>
<a name="l00011"></a>00011 <span class="comment"> * $$</span>
<a name="l00012"></a>00012 <span class="comment"> */</span>
<a name="l00013"></a>00013 
<a name="l00026"></a>00026 <span class="preprocessor">#include &lt;stdint.h&gt;</span>
<a name="l00027"></a>00027 <span class="preprocessor">#include &lt;string.h&gt;</span>
<a name="l00028"></a>00028 <span class="preprocessor">#include &quot;<a class="code" href="nordic__common_8h.html" title="Common defines and macros for firmware developed by Nordic Semiconductor.">nordic_common.h</a>&quot;</span>
<a name="l00029"></a>00029 <span class="preprocessor">#include &quot;nrf.h&quot;</span>
<a name="l00030"></a>00030 <span class="preprocessor">#include &quot;<a class="code" href="nrf__assert_8h.html" title="Utilities for verifying program logic.">nrf_assert.h</a>&quot;</span>
<a name="l00031"></a>00031 <span class="preprocessor">#include &quot;nrf_error.h&quot;</span>
<a name="l00032"></a>00032 <span class="preprocessor">#include &quot;nrf_gpio.h&quot;</span>
<a name="l00033"></a>00033 <span class="preprocessor">#include &quot;nrf51_bitfields.h&quot;</span>
<a name="l00034"></a>00034 <span class="preprocessor">#include &quot;ble.h&quot;</span>
<a name="l00035"></a>00035 <span class="preprocessor">#include &quot;ble_hci.h&quot;</span>
<a name="l00036"></a>00036 <span class="preprocessor">#include &quot;<a class="code" href="ble__srv__common_8h.html">ble_srv_common.h</a>&quot;</span>
<a name="l00037"></a>00037 <span class="preprocessor">#include &quot;<a class="code" href="ble__advdata_8h.html">ble_advdata.h</a>&quot;</span>
<a name="l00038"></a>00038 <span class="preprocessor">#include &quot;<a class="code" href="ble__bas_8h.html">ble_bas.h</a>&quot;</span>
<a name="l00039"></a>00039 <span class="preprocessor">#include &quot;<a class="code" href="ble__hrs_8h.html">ble_hrs.h</a>&quot;</span>
<a name="l00040"></a>00040 <span class="preprocessor">#include &quot;<a class="code" href="ble__dis_8h.html">ble_dis.h</a>&quot;</span>
<a name="l00041"></a>00041 <span class="preprocessor">#include &quot;<a class="code" href="ble__conn__params_8h.html">ble_conn_params.h</a>&quot;</span>
<a name="l00042"></a>00042 <span class="preprocessor">#include &quot;<a class="code" href="ble__nrf6310__pins_8h.html">ble_nrf6310_pins.h</a>&quot;</span>
<a name="l00043"></a>00043 <span class="preprocessor">#include &quot;<a class="code" href="ble__sensorsim_8h.html">ble_sensorsim.h</a>&quot;</span>
<a name="l00044"></a>00044 <span class="preprocessor">#include &quot;<a class="code" href="ble__stack__handler_8h.html">ble_stack_handler.h</a>&quot;</span>
<a name="l00045"></a>00045 <span class="preprocessor">#include &quot;<a class="code" href="app__timer_8h.html">app_timer.h</a>&quot;</span>
<a name="l00046"></a>00046 
<a name="l00047"></a>00047 
<a name="l00048"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#ga5f5a2c9450ebc584b4fe743c6b1a280b">00048</a> <span class="preprocessor">#define DEVICE_NAME                          &quot;HRS_APPV0.1&quot;                              </span>
<a name="l00049"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#gaaa2b8f5b105c3019df0cb346f472e803">00049</a> <span class="preprocessor">#define MANUFACTURER_NAME                    &quot;NordicSemiconductor&quot;                      </span>
<a name="l00050"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#gadde0b932e57e128e4cd81c2dca47cfe3">00050</a> <span class="preprocessor">#define APP_ADV_INTERVAL                     40                                         </span>
<a name="l00051"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#gaf58371bad8e1be8e2323df60379ed2df">00051</a> <span class="preprocessor">#define APP_ADV_TIMEOUT_IN_SECONDS           180                                        </span>
<a name="l00053"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#gaf28f0232a3fdc0eb03b94eb34b25cde8">00053</a> <span class="preprocessor">#define BATTERY_LEVEL_MEAS_INTERVAL          2000                                       </span>
<a name="l00054"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#ga59eb06cba38be11278ebd2829e95bc26">00054</a> <span class="preprocessor">#define MIN_BATTERY_LEVEL                    81                                         </span>
<a name="l00055"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#ga16896fb7a69ca90a4a4e341d5a888002">00055</a> <span class="preprocessor">#define MAX_BATTERY_LEVEL                    100                                        </span>
<a name="l00056"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#ga69eef02165834e4dabc5757b82dddbf1">00056</a> <span class="preprocessor">#define BATTERY_LEVEL_INCREMENT              1                                          </span>
<a name="l00058"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#ga45a3c3dc5dec56bf2ed3d1c4fdb0ccdd">00058</a> <span class="preprocessor">#define HEART_RATE_MEAS_INTERVAL             1000                                       </span>
<a name="l00059"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#ga8806d3ee13116211450e6fb3a2fb68a4">00059</a> <span class="preprocessor">#define MIN_HEART_RATE                       140                                        </span>
<a name="l00060"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#ga5c6a36078512a923ab07d1b8276c8cca">00060</a> <span class="preprocessor">#define MAX_HEART_RATE                       160                                        </span>
<a name="l00061"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#ga509bd9abefc38f3b7f60c389132c9b81">00061</a> <span class="preprocessor">#define HEART_RATE_INCREMENT                 1                                          </span>
<a name="l00063"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#ga9de92171573c36ded6e571be86716129">00063</a> <span class="preprocessor">#define RR_INTERVAL_INTERVAL                 300                                        </span>
<a name="l00064"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#gaeb7cf13d972734ca3c5e7b2ba037281e">00064</a> <span class="preprocessor">#define MIN_RR_INTERVAL                      100                                        </span>
<a name="l00065"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#ga11c7d3dc75939bf97dd4fcfce486f1de">00065</a> <span class="preprocessor">#define MAX_RR_INTERVAL                      500                                        </span>
<a name="l00066"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#gaabc91ee3f6543ceae2371ce367323cac">00066</a> <span class="preprocessor">#define RR_INTERVAL_INCREMENT                1                                          </span>
<a name="l00068"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#ga9922fc753e0f7eee90179b6d5f20f2c3">00068</a> <span class="preprocessor">#define SENSOR_CONTACT_DETECTED_INTERVAL     5000                                       </span>
<a name="l00070"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#ga95196d5d0f40cf195a6001955d6d98cf">00070</a> <span class="preprocessor">#define MIN_CONN_INTERVAL                    ((1 * 800) / 2)                            </span>
<a name="l00071"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#ga7d868ed8adb7d475b463fd8855907a18">00071</a> <span class="preprocessor">#define MAX_CONN_INTERVAL                    (1 * 800)                                  </span>
<a name="l00072"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#ga0c921a874ac37870fc1516ce66cd228a">00072</a> <span class="preprocessor">#define SLAVE_LATENCY                        0                                          </span>
<a name="l00073"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#ga799412c2b531ca347e13611e6e7523b9">00073</a> <span class="preprocessor">#define CONN_SUP_TIMEOUT                     (4 * 100)                                  </span>
<a name="l00074"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#ga7204f7a367e8f1ac53ef62c4ad220efc">00074</a> <span class="preprocessor">#define FIRST_CONN_PARAMS_UPDATE_DELAY       5000                                       </span>
<a name="l00075"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#gadf85796ef07632ed27e0bce9509d9245">00075</a> <span class="preprocessor">#define NEXT_CONN_PARAMS_UPDATE_DELAY        5000                                       </span>
<a name="l00076"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#ga34db81384bfbef23dedbef9bc6dfe46c">00076</a> <span class="preprocessor">#define MAX_CONN_PARAMS_UPDATE_COUNT         3                                          </span>
<a name="l00078"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#ga7c1fffb0f865552108560d4c63b32db1">00078</a> <span class="preprocessor">#define SEC_PARAM_TIMEOUT                    60                                         </span>
<a name="l00079"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#gacbf03a82593c273743a5a80a1119b851">00079</a> <span class="preprocessor">#define SEC_PARAM_BOND                       1                                          </span>
<a name="l00080"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#gab6831ebe113f8afe970326b7742b5947">00080</a> <span class="preprocessor">#define SEC_PARAM_MITM                       0                                          </span>
<a name="l00081"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#ga42df85b3a4083cdc614d9111d580d98f">00081</a> <span class="preprocessor">#define SEC_PARAM_IO_CAPABILITIES            BLE_GAP_IO_CAPS_NONE                       </span>
<a name="l00082"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#gaee13a0d0077f423fa0edd74e17fb6b88">00082</a> <span class="preprocessor">#define SEC_PARAM_OOB                        0                                          </span>
<a name="l00083"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#ga6b7b2e2f67fbf790f55b46f8f5e24ad5">00083</a> <span class="preprocessor">#define SEC_PARAM_MIN_KEY_SIZE               7                                          </span>
<a name="l00084"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#gaf2cd1595de153ea1d6d843619a1a7707">00084</a> <span class="preprocessor">#define SEC_PARAM_MAX_KEY_SIZE               16                                         </span>
<a name="l00086"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#gaaf76d22968f9f320aa5005a25f654320">00086</a> <span class="preprocessor">static uint16_t                              s_conn_handle = BLE_CONN_HANDLE_INVALID;   </span>
<a name="l00087"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#ga738ed84e141ba1059dd1318dc425343c">00087</a> <span class="preprocessor">static ble_gap_sec_params_t                  s_sec_params;                              </span>
<a name="l00088"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#ga50483ecf69a0ae87ce1a8a5e8fa73c04">00088</a> <span class="preprocessor">static ble_gap_adv_params_t                  s_adv_params;                              </span>
<a name="l00089"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#gab22f840926bbada5a0ba32f2f7dc94b3">00089</a> <span class="preprocessor">static ble_bas_t                             s_bas;                                     </span>
<a name="l00090"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#ga3e49fa0f1c47f72e98bc05de96dd24d4">00090</a> <span class="preprocessor">static ble_hrs_t                             s_hrs;                                     </span>
<a name="l00091"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#gaa4b03af66dfd69f347aad6c9bf06f989">00091</a> <span class="preprocessor">static bool                                  s_rr_interval_enabled = true;              </span>
<a name="l00093"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#gaa752585d9b405d6e0c6fd392d7f64b59">00093</a> <span class="preprocessor">static ble_sensorsim_cfg_t                   s_battery_sim_cfg;                         </span>
<a name="l00094"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#gaa51f5fc284e1b7e1570ab742fa9b63f3">00094</a> <span class="preprocessor">static ble_sensorsim_state_t                 s_battery_sim_state;                       </span>
<a name="l00095"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#ga39e135ff0a64d6761269e856a46b8afe">00095</a> <span class="preprocessor">static ble_sensorsim_cfg_t                   s_heart_rate_sim_cfg;                      </span>
<a name="l00096"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#ga267115c7f20ec331261551282d0ce0c1">00096</a> <span class="preprocessor">static ble_sensorsim_state_t                 s_heart_rate_sim_state;                    </span>
<a name="l00097"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#ga290a111981b0b7a7421cd249be9da006">00097</a> <span class="preprocessor">static ble_sensorsim_cfg_t                   s_rr_interval_sim_cfg;                     </span>
<a name="l00098"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#gab8ed76f872599bde36873ea4702e752b">00098</a> <span class="preprocessor">static ble_sensorsim_state_t                 s_rr_interval_sim_state;                   </span>
<a name="l00108"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#gadec561788a76b8a63ad9663625a25d78">00108</a> <span class="preprocessor">void assert_nrf_callback(uint16_t line_num, const uint8_t * file_name)</span>
<a name="l00109"></a>00109 <span class="preprocessor"></span>{
<a name="l00110"></a>00110     <span class="comment">// Copying parameters to static variables because parameters are not accessible in debugger</span>
<a name="l00111"></a>00111     <span class="keyword">static</span> <span class="keyword">volatile</span> uint8_t  s_file_name[128];
<a name="l00112"></a>00112     <span class="keyword">static</span> <span class="keyword">volatile</span> uint16_t s_line_num;
<a name="l00113"></a>00113 
<a name="l00114"></a>00114     strcpy((<span class="keywordtype">char</span> *)s_file_name, (<span class="keyword">const</span> <span class="keywordtype">char</span> *)file_name);
<a name="l00115"></a>00115     s_line_num = line_num;
<a name="l00116"></a>00116     UNUSED_VARIABLE(s_file_name);
<a name="l00117"></a>00117     UNUSED_VARIABLE(s_line_num);
<a name="l00118"></a>00118     
<a name="l00119"></a>00119     <a class="code" href="group__nrf__gpio.html#gacaf7e8e242a47f7b635bbeca5c5934a3" title="Set GPIO pin.">nrf_gpio_pin_set</a>(ASSERT_LED_PIN_NO);
<a name="l00120"></a>00120 
<a name="l00121"></a>00121     <span class="keywordflow">for</span> (;;)
<a name="l00122"></a>00122     {
<a name="l00123"></a>00123         <span class="comment">// Loop forever. On assert, the system can only recover on reset</span>
<a name="l00124"></a>00124     }
<a name="l00125"></a>00125 }
<a name="l00126"></a>00126 
<a name="l00127"></a>00127 
<a name="l00130"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#gab155022684d4acfd98218c3799822e74">00130</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hrs__main.html#gab155022684d4acfd98218c3799822e74" title="Perform battery measurement, and update Battery Level characteristic in Battery Service.">battery_level_update</a>(<span class="keywordtype">void</span>)
<a name="l00131"></a>00131 {
<a name="l00132"></a>00132     uint32_t err_code;
<a name="l00133"></a>00133     uint8_t  battery_level;
<a name="l00134"></a>00134     
<a name="l00135"></a>00135     battery_level = (uint8_t)<a class="code" href="group__ble__sdk__lib__sensorsim.html#gae73b8f0f956e0708e16d160605318ba8" title="Generate a simulated sensor measurement using a triangular waveform generator.">ble_sensorsim_measure</a>(&amp;<a class="code" href="group__ble__sdk__app__hrs__main.html#gaa51f5fc284e1b7e1570ab742fa9b63f3">s_battery_sim_state</a>, &amp;<a class="code" href="group__ble__sdk__app__hrs__main.html#gaa752585d9b405d6e0c6fd392d7f64b59">s_battery_sim_cfg</a>);
<a name="l00136"></a>00136     
<a name="l00137"></a>00137     err_code = <a class="code" href="group__ble__sdk__srv__bas.html#ga58d8f4336cce49ea5b3a2f8997bfe00e" title="Update battery level.">ble_bas_battery_level_update</a>(&amp;<a class="code" href="group__ble__sdk__app__hrs__main.html#gab22f840926bbada5a0ba32f2f7dc94b3">s_bas</a>, battery_level);
<a name="l00138"></a>00138     <span class="keywordflow">if</span> (
<a name="l00139"></a>00139         (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00140"></a>00140         &amp;&amp;
<a name="l00141"></a>00141         (err_code != <a class="code" href="group__nrf__error.html#gaf0aff2ba7864b34a36b4a96986e1851e" title="Invalid state, operation disallowed in this state.">NRF_ERROR_INVALID_STATE</a>)
<a name="l00142"></a>00142         &amp;&amp;
<a name="l00143"></a>00143         (err_code != <a class="code" href="group__ble__err.html#ga901e1bc3ccae29eff9fb31cabdbb5e02">BLE_ERROR_NO_TX_BUFFERS</a>)
<a name="l00144"></a>00144         &amp;&amp;
<a name="l00145"></a>00145         (err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
<a name="l00146"></a>00146     )
<a name="l00147"></a>00147     {
<a name="l00148"></a>00148         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00149"></a>00149     }
<a name="l00150"></a>00150 }
<a name="l00151"></a>00151 
<a name="l00152"></a>00152 
<a name="l00159"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#ga7e5b3d2cf024dde83b8c536b22a1c155">00159</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hrs__main.html#ga7e5b3d2cf024dde83b8c536b22a1c155" title="Battery measurement timer timeout handler.">battery_level_meas_timeout_handler</a>(app_timer_id_t timer_id)
<a name="l00160"></a>00160 {
<a name="l00161"></a>00161     <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(timer_id == APP_TIMER_BATTERY_LEVEL_MEAS);
<a name="l00162"></a>00162     <a class="code" href="group__ble__sdk__app__hrs__main.html#gab155022684d4acfd98218c3799822e74" title="Perform battery measurement, and update Battery Level characteristic in Battery Service.">battery_level_update</a>();
<a name="l00163"></a>00163 }
<a name="l00164"></a>00164 
<a name="l00165"></a>00165 
<a name="l00173"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#ga5f2bc03dde9dbfbd8983fdf45085d55b">00173</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hrs__main.html#ga5f2bc03dde9dbfbd8983fdf45085d55b" title="Heart rate measurement timer timeout handler.">heart_rate_meas_timeout_handler</a>(app_timer_id_t timer_id)
<a name="l00174"></a>00174 {
<a name="l00175"></a>00175     <span class="keyword">static</span> uint32_t cnt = 0;
<a name="l00176"></a>00176     uint32_t        err_code;
<a name="l00177"></a>00177     uint16_t        heart_rate;
<a name="l00178"></a>00178     
<a name="l00179"></a>00179     <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(timer_id == APP_TIMER_HEART_RATE_MEAS);
<a name="l00180"></a>00180 
<a name="l00181"></a>00181     heart_rate = (uint16_t)<a class="code" href="group__ble__sdk__lib__sensorsim.html#gae73b8f0f956e0708e16d160605318ba8" title="Generate a simulated sensor measurement using a triangular waveform generator.">ble_sensorsim_measure</a>(&amp;<a class="code" href="group__ble__sdk__app__hrs__main.html#ga267115c7f20ec331261551282d0ce0c1">s_heart_rate_sim_state</a>, &amp;<a class="code" href="group__ble__sdk__app__hrs__main.html#ga39e135ff0a64d6761269e856a46b8afe">s_heart_rate_sim_cfg</a>);
<a name="l00182"></a>00182 
<a name="l00183"></a>00183     cnt++;
<a name="l00184"></a>00184     err_code = <a class="code" href="group__ble__sdk__srv__hrs.html#gabe5fed48baeb4a518a51bd7e2e5f010e" title="Sends heart rate measurement if notification has been enabled.">ble_hrs_heart_rate_measurement_send</a>(&amp;<a class="code" href="group__ble__sdk__app__hrs__main.html#ga3e49fa0f1c47f72e98bc05de96dd24d4">s_hrs</a>, heart_rate);
<a name="l00185"></a>00185     <span class="keywordflow">if</span> (
<a name="l00186"></a>00186         (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00187"></a>00187         &amp;&amp;
<a name="l00188"></a>00188         (err_code != <a class="code" href="group__nrf__error.html#gaf0aff2ba7864b34a36b4a96986e1851e" title="Invalid state, operation disallowed in this state.">NRF_ERROR_INVALID_STATE</a>)
<a name="l00189"></a>00189         &amp;&amp;
<a name="l00190"></a>00190         (err_code != <a class="code" href="group__ble__err.html#ga901e1bc3ccae29eff9fb31cabdbb5e02">BLE_ERROR_NO_TX_BUFFERS</a>)
<a name="l00191"></a>00191         &amp;&amp;
<a name="l00192"></a>00192         (err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
<a name="l00193"></a>00193     )
<a name="l00194"></a>00194     {
<a name="l00195"></a>00195         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00196"></a>00196     }
<a name="l00197"></a>00197     
<a name="l00198"></a>00198     <span class="comment">// Disable RR Interval recording every third heart rate measurement.</span>
<a name="l00199"></a>00199     <span class="comment">// NOTE: An application will normally not do this. It is done here just for testing generation</span>
<a name="l00200"></a>00200     <span class="comment">//       of messages without RR Interval measurements.</span>
<a name="l00201"></a>00201     <a class="code" href="group__ble__sdk__app__hrs__main.html#gaa4b03af66dfd69f347aad6c9bf06f989">s_rr_interval_enabled</a> = ((cnt % 3) != 0);
<a name="l00202"></a>00202 }
<a name="l00203"></a>00203 
<a name="l00204"></a>00204 
<a name="l00211"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#ga9cb0ab1ccfd2d0873091c3a76b7177af">00211</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hrs__main.html#ga9cb0ab1ccfd2d0873091c3a76b7177af" title="RR interval timer timeout handler.">rr_interval_timeout_handler</a>(app_timer_id_t timer_id)
<a name="l00212"></a>00212 {
<a name="l00213"></a>00213     <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(timer_id == APP_TIMER_RR_INTERVAL);
<a name="l00214"></a>00214     <span class="keywordflow">if</span> (<a class="code" href="group__ble__sdk__app__hrs__main.html#gaa4b03af66dfd69f347aad6c9bf06f989">s_rr_interval_enabled</a>)
<a name="l00215"></a>00215     {
<a name="l00216"></a>00216         uint16_t rr_interval;
<a name="l00217"></a>00217         
<a name="l00218"></a>00218         rr_interval = (uint16_t)<a class="code" href="group__ble__sdk__lib__sensorsim.html#gae73b8f0f956e0708e16d160605318ba8" title="Generate a simulated sensor measurement using a triangular waveform generator.">ble_sensorsim_measure</a>(&amp;<a class="code" href="group__ble__sdk__app__hrs__main.html#gab8ed76f872599bde36873ea4702e752b">s_rr_interval_sim_state</a>,
<a name="l00219"></a>00219                                                       &amp;<a class="code" href="group__ble__sdk__app__hrs__main.html#ga290a111981b0b7a7421cd249be9da006">s_rr_interval_sim_cfg</a>);
<a name="l00220"></a>00220         <a class="code" href="group__ble__sdk__srv__hrs.html#gaea316a9c9503571b143d93086295f61a" title="Adds a RR Interval measurement to the RR Interval buffer.">ble_hrs_rr_interval_add</a>(&amp;<a class="code" href="group__ble__sdk__app__hrs__main.html#ga3e49fa0f1c47f72e98bc05de96dd24d4">s_hrs</a>, rr_interval);
<a name="l00221"></a>00221     }
<a name="l00222"></a>00222 }
<a name="l00223"></a>00223 
<a name="l00224"></a>00224 
<a name="l00231"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#gac05c2186395218b520bdad865660f44d">00231</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hrs__main.html#gac05c2186395218b520bdad865660f44d" title="Sensor Contact Detected timer timeout handler.">sensor_contact_detected_timeout_handler</a>(app_timer_id_t timer_id)
<a name="l00232"></a>00232 {
<a name="l00233"></a>00233     <span class="keyword">static</span> <span class="keywordtype">bool</span> sensor_contact_detected = <span class="keyword">false</span>;
<a name="l00234"></a>00234     
<a name="l00235"></a>00235     <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(timer_id == APP_TIMER_SENSOR_CONTACT_DETECTED);
<a name="l00236"></a>00236     sensor_contact_detected = !sensor_contact_detected;
<a name="l00237"></a>00237     <a class="code" href="group__ble__sdk__srv__hrs.html#ga4eccea2cb1d248ccdc75bebb84c1dff2" title="Sets the state of the Sensor Contact Detected bit.">ble_hrs_sensor_contact_detected_update</a>(&amp;<a class="code" href="group__ble__sdk__app__hrs__main.html#ga3e49fa0f1c47f72e98bc05de96dd24d4">s_hrs</a>, sensor_contact_detected);
<a name="l00238"></a>00238 }
<a name="l00239"></a>00239 
<a name="l00240"></a>00240 
<a name="l00245"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#ga0892e076b365fc49b55bd0f90ab09222">00245</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__gzll__ui.html#ga67cfc3137a465e560792490e81365254" title="LEDs initialization.">leds_init</a>(<span class="keywordtype">void</span>)
<a name="l00246"></a>00246 {
<a name="l00247"></a>00247     <a class="code" href="group__ble__sdk__lib__util.html#ga3f8d3d1b629cf9a61a86886059987e6a" title="Configure a PIN to be used as a LED.">GPIO_LED_CONFIG</a>(ADVERTISING_LED_PIN_NO);
<a name="l00248"></a>00248     <a class="code" href="group__ble__sdk__lib__util.html#ga3f8d3d1b629cf9a61a86886059987e6a" title="Configure a PIN to be used as a LED.">GPIO_LED_CONFIG</a>(CONNECTED_LED_PIN_NO);
<a name="l00249"></a>00249     <a class="code" href="group__ble__sdk__lib__util.html#ga3f8d3d1b629cf9a61a86886059987e6a" title="Configure a PIN to be used as a LED.">GPIO_LED_CONFIG</a>(ASSERT_LED_PIN_NO);
<a name="l00250"></a>00250 }
<a name="l00251"></a>00251 
<a name="l00252"></a>00252 
<a name="l00257"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#ga09658aaa0774820d8f25249d551bc283">00257</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hrs__main.html#ga09658aaa0774820d8f25249d551bc283" title="Timer initialization.">timers_init</a>(<span class="keywordtype">void</span>)
<a name="l00258"></a>00258 {
<a name="l00259"></a>00259     uint32_t err_code;
<a name="l00260"></a>00260     
<a name="l00261"></a>00261     <span class="comment">// Initialize timer module</span>
<a name="l00262"></a>00262     err_code = <a class="code" href="group__app__timer.html#ga4e1da5a2f64ee78ee97f7422ea97e439" title="Initializes the timer module.">app_timer_init</a>(NULL);
<a name="l00263"></a>00263     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00264"></a>00264     {
<a name="l00265"></a>00265         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00266"></a>00266     }
<a name="l00267"></a>00267 }
<a name="l00268"></a>00268 
<a name="l00269"></a>00269 
<a name="l00275"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#ga1004973353f351806e42896c491a5ab2">00275</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hrs__main.html#ga1004973353f351806e42896c491a5ab2" title="GAP initialization.">gap_params_init</a>(<span class="keywordtype">void</span>)
<a name="l00276"></a>00276 {
<a name="l00277"></a>00277     uint32_t                err_code;
<a name="l00278"></a>00278     <a class="code" href="structble__gap__conn__params__t.html" title="GAP connection parameters.">ble_gap_conn_params_t</a>   gap_conn_params;
<a name="l00279"></a>00279     <a class="code" href="structble__gap__conn__sec__mode__t.html" title="GAP link requirements.">ble_gap_conn_sec_mode_t</a> sec_mode;
<a name="l00280"></a>00280 
<a name="l00281"></a>00281     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga2abd1c711d49a4d4b1ab9bf27cafffbb" title="Set sec_mode pointed to by ptr to require no protection, open link.">BLE_GAP_CONN_SEC_MODE_SET_OPEN</a>(&amp;sec_mode);
<a name="l00282"></a>00282     
<a name="l00283"></a>00283     err_code = <a class="code" href="group___b_l_e___g_a_p.html#ga7d665aa56f8d248b8779a6cf170e2052" title="Set GAP device name.">ble_gap_device_name_set</a>(&amp;sec_mode, <a class="code" href="group__ble__sdk__app__hrs__main.html#ga5f5a2c9450ebc584b4fe743c6b1a280b">DEVICE_NAME</a>);
<a name="l00284"></a>00284     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00285"></a>00285     {
<a name="l00286"></a>00286         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00287"></a>00287     }
<a name="l00288"></a>00288 
<a name="l00289"></a>00289     err_code = <a class="code" href="group___b_l_e___g_a_p.html#ga711f129fb97e0071ab04d2e994125f7a" title="Set GAP Appearance field.">ble_gap_appearance_set</a>(<a class="code" href="group___b_l_e___a_p_p_e_a_r_a_n_c_e_s.html#ga590996bfcab479b91c41ee10060e3ce7">BLE_APPEARANCE_HEART_RATE_SENSOR_HEART_RATE_BELT</a>);
<a name="l00290"></a>00290     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00291"></a>00291     {
<a name="l00292"></a>00292         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00293"></a>00293     }
<a name="l00294"></a>00294     
<a name="l00295"></a>00295     memset(&amp;gap_conn_params, 0, <span class="keyword">sizeof</span>(gap_conn_params));
<a name="l00296"></a>00296 
<a name="l00297"></a>00297     gap_conn_params.<a class="code" href="structble__gap__conn__params__t.html#ac927a642ee2203f875fcce1eabb5fa64">min_conn_interval</a> = <a class="code" href="group__ble__sdk__app__hrs__main.html#ga95196d5d0f40cf195a6001955d6d98cf">MIN_CONN_INTERVAL</a>;
<a name="l00298"></a>00298     gap_conn_params.<a class="code" href="structble__gap__conn__params__t.html#a0aec1884f340406a5194b772da017d7b">max_conn_interval</a> = <a class="code" href="group__ble__sdk__app__hrs__main.html#ga7d868ed8adb7d475b463fd8855907a18">MAX_CONN_INTERVAL</a>;
<a name="l00299"></a>00299     gap_conn_params.<a class="code" href="structble__gap__conn__params__t.html#a39219ac00a0e8ed843ee32b9df8be11e">slave_latency</a>     = <a class="code" href="group__ble__sdk__app__hrs__main.html#ga0c921a874ac37870fc1516ce66cd228a">SLAVE_LATENCY</a>;
<a name="l00300"></a>00300     gap_conn_params.<a class="code" href="structble__gap__conn__params__t.html#a2089e7fb26f6b24882d1437eb5553bc7">conn_sup_timeout</a>  = <a class="code" href="group__ble__sdk__app__hrs__main.html#ga799412c2b531ca347e13611e6e7523b9">CONN_SUP_TIMEOUT</a>;
<a name="l00301"></a>00301 
<a name="l00302"></a>00302     err_code = <a class="code" href="group___b_l_e___g_a_p.html#ga28e0062141d77d7b2272fc3a6b6e17c5" title="Set GAP Peripheral Preferred Connection Parameters.">ble_gap_ppcp_set</a>(&amp;gap_conn_params);
<a name="l00303"></a>00303     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00304"></a>00304     {
<a name="l00305"></a>00305         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00306"></a>00306     }
<a name="l00307"></a>00307 }
<a name="l00308"></a>00308 
<a name="l00309"></a>00309 
<a name="l00315"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#ga935c9624de0709fe228dbefa4b54de48">00315</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hrs__main.html#ga935c9624de0709fe228dbefa4b54de48" title="Advertising functionality initialization.">advertising_init</a>(<span class="keywordtype">void</span>)
<a name="l00316"></a>00316 {
<a name="l00317"></a>00317     uint32_t      err_code;
<a name="l00318"></a>00318     <a class="code" href="structble__advdata__t.html" title="Advertising data structure. This contains all options and data needed for encoding and setting the ad...">ble_advdata_t</a> advdata;
<a name="l00319"></a>00319     uint8_t       flags = <a class="code" href="group___b_l_e___g_a_p___d_i_s_c___m_o_d_e_s.html#ga124514248a211b305eeac9cc370c7d77">BLE_GAP_DISC_MODE_GENERAL</a> | <a class="code" href="group___b_l_e___g_a_p___d_i_s_c___m_o_d_e_s.html#ga346a5b47f4b8f94a08f320a0d8c14c18">BLE_GAP_DISC_BR_EDR_NOT_SUPPORTED</a>;
<a name="l00320"></a>00320     
<a name="l00321"></a>00321     <a class="code" href="structble__uuid__t.html" title="Bluetooth Low Energy UUID type, encapsulates both 16-bit and 128-bit UUIDs.">ble_uuid_t</a> adv_uuids[] = 
<a name="l00322"></a>00322     {
<a name="l00323"></a>00323         {<a class="code" href="group___u_u_i_d___s_e_r_v_i_c_e_s.html#gada8a8d4952d86f3557365ce0ead40e15">BLE_UUID_HEART_RATE_SERVICE</a>,         <a class="code" href="group___b_l_e___u_u_i_d___t_y_p_e_s.html#gae549d14b15783ba52dae5fdd5f9ac959">BLE_UUID_TYPE_BLE</a>}, 
<a name="l00324"></a>00324         {<a class="code" href="group___u_u_i_d___s_e_r_v_i_c_e_s.html#ga4090520f3007fe6f90f06a6f4f8d5845">BLE_UUID_BATTERY_SERVICE</a>,            <a class="code" href="group___b_l_e___u_u_i_d___t_y_p_e_s.html#gae549d14b15783ba52dae5fdd5f9ac959">BLE_UUID_TYPE_BLE</a>}, 
<a name="l00325"></a>00325         {<a class="code" href="group___u_u_i_d___s_e_r_v_i_c_e_s.html#gab8eac87431b53cdfaeccd6d3a15ed5ac">BLE_UUID_DEVICE_INFORMATION_SERVICE</a>, <a class="code" href="group___b_l_e___u_u_i_d___t_y_p_e_s.html#gae549d14b15783ba52dae5fdd5f9ac959">BLE_UUID_TYPE_BLE</a>}
<a name="l00326"></a>00326     };
<a name="l00327"></a>00327 
<a name="l00328"></a>00328     <span class="comment">// Build and set advertising data</span>
<a name="l00329"></a>00329     memset(&amp;advdata, 0, <span class="keyword">sizeof</span>(advdata));
<a name="l00330"></a>00330     
<a name="l00331"></a>00331     advdata.<a class="code" href="structble__advdata__t.html#a045ec5915c094e107ac24d185b83fa49">name_type</a>               = <a class="code" href="group__ble__sdk__lib__advdata.html#gga03c5ccf232779001be9786021b1a563ba63a26e22b9d6a0899edac755d0e2f488">BLE_ADVDATA_FULL_NAME</a>;
<a name="l00332"></a>00332     advdata.<a class="code" href="structble__advdata__t.html#aff2bb3e4016b9a7b6cbcdd6e98feb719">include_appearance</a>      = <span class="keyword">true</span>;
<a name="l00333"></a>00333     advdata.<a class="code" href="structble__advdata__t.html#a3ad6b2c5a983e0f2676c85c546ed47ae">flags</a>.<a class="code" href="structuint8__array__t.html#aaba88b24a21a6c70c895c0d55f4a69a0">size</a>              = <span class="keyword">sizeof</span>(flags);
<a name="l00334"></a>00334     advdata.<a class="code" href="structble__advdata__t.html#a3ad6b2c5a983e0f2676c85c546ed47ae">flags</a>.<a class="code" href="structuint8__array__t.html#a8304c4af5da6e830b86d7199dc9a22e6">p_data</a>            = &amp;flags;
<a name="l00335"></a>00335     advdata.<a class="code" href="structble__advdata__t.html#af848e0d7e7334a53498e1e6c592fed90">uuids_complete</a>.<a class="code" href="structble__advdata__uuid__list__t.html#a1cecc52d144b939f33a67c1d68363e99">uuid_cnt</a> = <span class="keyword">sizeof</span>(adv_uuids) / <span class="keyword">sizeof</span>(adv_uuids[0]);
<a name="l00336"></a>00336     advdata.<a class="code" href="structble__advdata__t.html#af848e0d7e7334a53498e1e6c592fed90">uuids_complete</a>.<a class="code" href="structble__advdata__uuid__list__t.html#a100265d2ed10e66a76e53cba205dc8a3">p_uuids</a>  = adv_uuids;
<a name="l00337"></a>00337     
<a name="l00338"></a>00338     err_code = <a class="code" href="group__ble__sdk__lib__advdata.html#ga180ff4057a0763688c734e98ab8d976b" title="Encodes and sets the advertising data and/or scan response data.">ble_advdata_set</a>(&amp;advdata, NULL);
<a name="l00339"></a>00339     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00340"></a>00340     {
<a name="l00341"></a>00341         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00342"></a>00342     }
<a name="l00343"></a>00343 
<a name="l00344"></a>00344     <span class="comment">// Initialise advertising parameters (used when starting advertising)</span>
<a name="l00345"></a>00345     memset(&amp;<a class="code" href="group__ble__sdk__app__hrs__main.html#ga50483ecf69a0ae87ce1a8a5e8fa73c04">s_adv_params</a>, 0, <span class="keyword">sizeof</span>(<a class="code" href="group__ble__sdk__app__hrs__main.html#ga50483ecf69a0ae87ce1a8a5e8fa73c04">s_adv_params</a>));
<a name="l00346"></a>00346     
<a name="l00347"></a>00347     <a class="code" href="group__ble__sdk__app__hrs__main.html#ga50483ecf69a0ae87ce1a8a5e8fa73c04">s_adv_params</a>.<a class="code" href="structble__gap__adv__params__t.html#a1d127017fb298b889f4ba24752d08b8e">type</a>        = <a class="code" href="group___b_l_e___g_a_p___a_d_v___t_y_p_e_s.html#ga6cc0db53453977ee0a31e59f07de2b86">BLE_GAP_ADV_TYPE_ADV_IND</a>;
<a name="l00348"></a>00348     <a class="code" href="group__ble__sdk__app__hrs__main.html#ga50483ecf69a0ae87ce1a8a5e8fa73c04">s_adv_params</a>.<a class="code" href="structble__gap__adv__params__t.html#a27909d1b865548f236a871af2b6aa584">p_peer_addr</a> = NULL;                           <span class="comment">// Undirected advertisement</span>
<a name="l00349"></a>00349     <a class="code" href="group__ble__sdk__app__hrs__main.html#ga50483ecf69a0ae87ce1a8a5e8fa73c04">s_adv_params</a>.<a class="code" href="structble__gap__adv__params__t.html#aefdab55ee0f22565a03a14d09cc71d12">fp</a>          = <a class="code" href="group___b_l_e___g_a_p___a_d_v___f_i_l_t_e_r___p_o_l_i_c_i_e_s.html#ga0b0393df73db101d6cbfaede2dbb7ea6">BLE_GAP_ADV_FP_ANY</a>;
<a name="l00350"></a>00350     <a class="code" href="group__ble__sdk__app__hrs__main.html#ga50483ecf69a0ae87ce1a8a5e8fa73c04">s_adv_params</a>.<a class="code" href="structble__gap__adv__params__t.html#a6c52a3d605c056768b59164ce8df8334">interval</a>    = <a class="code" href="group__ble__sdk__app__hrs__main.html#gadde0b932e57e128e4cd81c2dca47cfe3">APP_ADV_INTERVAL</a>;
<a name="l00351"></a>00351     <a class="code" href="group__ble__sdk__app__hrs__main.html#ga50483ecf69a0ae87ce1a8a5e8fa73c04">s_adv_params</a>.<a class="code" href="structble__gap__adv__params__t.html#a7f1ad43d3bf79b40bc39dbb5a6c3a5ae">timeout</a>     = <a class="code" href="group__ble__sdk__app__hrs__main.html#gaf58371bad8e1be8e2323df60379ed2df">APP_ADV_TIMEOUT_IN_SECONDS</a>;
<a name="l00352"></a>00352 }
<a name="l00353"></a>00353 
<a name="l00354"></a>00354 
<a name="l00359"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#ga5b27b40e18af00d43b92f57eaed0e9b2">00359</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hrs__main.html#ga5b27b40e18af00d43b92f57eaed0e9b2" title="Initialize services that will be used by the application.">services_init</a>(<span class="keywordtype">void</span>)
<a name="l00360"></a>00360 {
<a name="l00361"></a>00361     uint32_t       err_code;
<a name="l00362"></a>00362     <a class="code" href="structble__hrs__init__t.html" title="Heart Rate Service init structure. This contains all options and data needed for initialization of th...">ble_hrs_init_t</a> hrs_init;
<a name="l00363"></a>00363     <a class="code" href="structble__bas__init__t.html" title="Battery Service init structure. This contains all options and data needed for initialization of the s...">ble_bas_init_t</a> <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga46507354f43dd16b32281f032e29d9c5" title="Initialize Battery Service.">bas_init</a>;
<a name="l00364"></a>00364     <a class="code" href="structble__dis__init__t.html" title="Device Information Service init structure. This contains all possible characteristics needed for init...">ble_dis_init_t</a> <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga2d0743f12929b17b64c5c2fb101a9350" title="Initialize Device Information Service.">dis_init</a>;
<a name="l00365"></a>00365     uint8_t        body_sensor_location;
<a name="l00366"></a>00366     
<a name="l00367"></a>00367     <span class="comment">// Initialize Heart Rate Service</span>
<a name="l00368"></a>00368     body_sensor_location = BLE_HRS_BODY_SENSOR_LOCATION_FINGER;
<a name="l00369"></a>00369     
<a name="l00370"></a>00370     memset(&amp;hrs_init, 0, <span class="keyword">sizeof</span>(hrs_init));
<a name="l00371"></a>00371     
<a name="l00372"></a>00372     hrs_init.<a class="code" href="structble__hrs__init__t.html#ae1a260338589ff1393ed4e142c3b6114">evt_handler</a>                 = NULL;
<a name="l00373"></a>00373     hrs_init.<a class="code" href="structble__hrs__init__t.html#a72fb2dea328affc259a55ca2447d0a48">is_sensor_contact_supported</a> = <span class="keyword">true</span>;
<a name="l00374"></a>00374     hrs_init.<a class="code" href="structble__hrs__init__t.html#a89a0f7e39b46019e49fb392689f6073c">p_body_sensor_location</a>      = &amp;body_sensor_location;
<a name="l00375"></a>00375 
<a name="l00376"></a>00376     <span class="comment">// Here the sec level for the Heart Rate Service can be changed/increased.</span>
<a name="l00377"></a>00377     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga2abd1c711d49a4d4b1ab9bf27cafffbb" title="Set sec_mode pointed to by ptr to require no protection, open link.">BLE_GAP_CONN_SEC_MODE_SET_OPEN</a>(&amp;hrs_init.<a class="code" href="structble__hrs__init__t.html#a670a4c608f847ac03bd66005b30068c3">hrs_hrm_attr_md</a>.cccd_write_perm);
<a name="l00378"></a>00378     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga1cf3822f8bb11e28931afbb9179665b7" title="Set sec_mode pointed to by ptr to have no access rights.">BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS</a>(&amp;hrs_init.<a class="code" href="structble__hrs__init__t.html#a670a4c608f847ac03bd66005b30068c3">hrs_hrm_attr_md</a>.<a class="code" href="structble__srv__cccd__security__mode__t.html#af0352a482ca2a1305ec5941bc4af0ec2">read_perm</a>);
<a name="l00379"></a>00379     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga1cf3822f8bb11e28931afbb9179665b7" title="Set sec_mode pointed to by ptr to have no access rights.">BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS</a>(&amp;hrs_init.<a class="code" href="structble__hrs__init__t.html#a670a4c608f847ac03bd66005b30068c3">hrs_hrm_attr_md</a>.<a class="code" href="structble__srv__cccd__security__mode__t.html#a6060006e42afe1970aed0a8490f71445">write_perm</a>);
<a name="l00380"></a>00380 
<a name="l00381"></a>00381     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga2abd1c711d49a4d4b1ab9bf27cafffbb" title="Set sec_mode pointed to by ptr to require no protection, open link.">BLE_GAP_CONN_SEC_MODE_SET_OPEN</a>(&amp;hrs_init.<a class="code" href="structble__hrs__init__t.html#a2b688c05a8f04acd31acf2c55c3efc84">hrs_bsl_attr_md</a>.<a class="code" href="structble__srv__security__mode__t.html#af0352a482ca2a1305ec5941bc4af0ec2">read_perm</a>);
<a name="l00382"></a>00382     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga1cf3822f8bb11e28931afbb9179665b7" title="Set sec_mode pointed to by ptr to have no access rights.">BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS</a>(&amp;hrs_init.<a class="code" href="structble__hrs__init__t.html#a2b688c05a8f04acd31acf2c55c3efc84">hrs_bsl_attr_md</a>.<a class="code" href="structble__srv__security__mode__t.html#a6060006e42afe1970aed0a8490f71445">write_perm</a>);
<a name="l00383"></a>00383 
<a name="l00384"></a>00384     err_code = <a class="code" href="group__ble__sdk__srv__hrs.html#ga94256c7eb29129ff352ca53adf1ad5b8" title="Initialize the Heart Rate Service.">ble_hrs_init</a>(&amp;<a class="code" href="group__ble__sdk__app__hrs__main.html#ga3e49fa0f1c47f72e98bc05de96dd24d4">s_hrs</a>, &amp;hrs_init);
<a name="l00385"></a>00385     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00386"></a>00386     {
<a name="l00387"></a>00387         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00388"></a>00388     }
<a name="l00389"></a>00389     
<a name="l00390"></a>00390     <span class="comment">// Initialize Battery Service</span>
<a name="l00391"></a>00391     memset(&amp;bas_init, 0, <span class="keyword">sizeof</span>(bas_init));
<a name="l00392"></a>00392     
<a name="l00393"></a>00393     <span class="comment">// Here the sec level for the Battery Service can be changed/increased.</span>
<a name="l00394"></a>00394     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga2abd1c711d49a4d4b1ab9bf27cafffbb" title="Set sec_mode pointed to by ptr to require no protection, open link.">BLE_GAP_CONN_SEC_MODE_SET_OPEN</a>(&amp;bas_init.<a class="code" href="structble__bas__init__t.html#ada6a205c81f51d9aa2de33bbdea0bd26">battery_level_char_attr_md</a>.cccd_write_perm);
<a name="l00395"></a>00395     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga2abd1c711d49a4d4b1ab9bf27cafffbb" title="Set sec_mode pointed to by ptr to require no protection, open link.">BLE_GAP_CONN_SEC_MODE_SET_OPEN</a>(&amp;bas_init.<a class="code" href="structble__bas__init__t.html#ada6a205c81f51d9aa2de33bbdea0bd26">battery_level_char_attr_md</a>.<a class="code" href="structble__srv__cccd__security__mode__t.html#af0352a482ca2a1305ec5941bc4af0ec2">read_perm</a>);
<a name="l00396"></a>00396     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga1cf3822f8bb11e28931afbb9179665b7" title="Set sec_mode pointed to by ptr to have no access rights.">BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS</a>(&amp;bas_init.<a class="code" href="structble__bas__init__t.html#ada6a205c81f51d9aa2de33bbdea0bd26">battery_level_char_attr_md</a>.<a class="code" href="structble__srv__cccd__security__mode__t.html#a6060006e42afe1970aed0a8490f71445">write_perm</a>);
<a name="l00397"></a>00397 
<a name="l00398"></a>00398     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga2abd1c711d49a4d4b1ab9bf27cafffbb" title="Set sec_mode pointed to by ptr to require no protection, open link.">BLE_GAP_CONN_SEC_MODE_SET_OPEN</a>(&amp;bas_init.<a class="code" href="structble__bas__init__t.html#a2c9724572f64316880f915bb78882de0">battery_level_report_read_perm</a>);
<a name="l00399"></a>00399 
<a name="l00400"></a>00400     bas_init.<a class="code" href="structble__bas__init__t.html#a3c25f96941dd8c1b92407ed2994691c6">evt_handler</a>          = NULL;
<a name="l00401"></a>00401     bas_init.<a class="code" href="structble__bas__init__t.html#adbf298550acd37c0d6170e90504318ac">support_notification</a> = <span class="keyword">true</span>;
<a name="l00402"></a>00402     bas_init.<a class="code" href="structble__bas__init__t.html#ac3ce984f1c066cfc0911e98fa1acdc8e">p_report_ref</a>         = NULL;
<a name="l00403"></a>00403     bas_init.<a class="code" href="structble__bas__init__t.html#ae5e656df4b847b3a099792ae32676d16">initial_batt_level</a>   = 100;
<a name="l00404"></a>00404     
<a name="l00405"></a>00405     err_code = <a class="code" href="group__ble__sdk__srv__bas.html#gacb8ac9205dcec39e216575c76261c807" title="Initialize the Battery Service.">ble_bas_init</a>(&amp;<a class="code" href="group__ble__sdk__app__hrs__main.html#gab22f840926bbada5a0ba32f2f7dc94b3">s_bas</a>, &amp;bas_init);
<a name="l00406"></a>00406     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00407"></a>00407     {
<a name="l00408"></a>00408         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00409"></a>00409     }
<a name="l00410"></a>00410 
<a name="l00411"></a>00411     <span class="comment">// Initialize Device Information Service</span>
<a name="l00412"></a>00412     memset(&amp;dis_init, 0, <span class="keyword">sizeof</span>(dis_init));
<a name="l00413"></a>00413     
<a name="l00414"></a>00414     <a class="code" href="group__ble__sdk__srv__common.html#ga611dfcf7209a57c2e45964e8bb4c5756" title="Make UTF-8 structure refer to an ASCII string.">ble_srv_ascii_to_utf8</a>(&amp;dis_init.<a class="code" href="structble__dis__init__t.html#a02a650cde3f65fc67f65b5fb4cd33425">manufact_name_str</a>, <a class="code" href="group__ble__sdk__app__hrs__main.html#gaaa2b8f5b105c3019df0cb346f472e803">MANUFACTURER_NAME</a>);
<a name="l00415"></a>00415 
<a name="l00416"></a>00416     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga2abd1c711d49a4d4b1ab9bf27cafffbb" title="Set sec_mode pointed to by ptr to require no protection, open link.">BLE_GAP_CONN_SEC_MODE_SET_OPEN</a>(&amp;dis_init.<a class="code" href="structble__dis__init__t.html#aa3268ab4659686cb4202651e071af265">dis_attr_md</a>.<a class="code" href="structble__srv__security__mode__t.html#af0352a482ca2a1305ec5941bc4af0ec2">read_perm</a>);
<a name="l00417"></a>00417     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga1cf3822f8bb11e28931afbb9179665b7" title="Set sec_mode pointed to by ptr to have no access rights.">BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS</a>(&amp;dis_init.<a class="code" href="structble__dis__init__t.html#aa3268ab4659686cb4202651e071af265">dis_attr_md</a>.<a class="code" href="structble__srv__security__mode__t.html#a6060006e42afe1970aed0a8490f71445">write_perm</a>);
<a name="l00418"></a>00418 
<a name="l00419"></a>00419     err_code = <a class="code" href="group__ble__sdk__srv__dis.html#ga472c83dfe2ad977d76b664095a4991cd" title="Initialize the Device Information Service.">ble_dis_init</a>(&amp;dis_init);
<a name="l00420"></a>00420     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00421"></a>00421     {
<a name="l00422"></a>00422         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00423"></a>00423     }
<a name="l00424"></a>00424 }
<a name="l00425"></a>00425 
<a name="l00426"></a>00426 
<a name="l00429"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#ga6f75e3fe8d4ed6400f9429987dee0f3e">00429</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hrs__main.html#ga6f75e3fe8d4ed6400f9429987dee0f3e" title="Initialize the sensor simulators.">sensor_sim_init</a>(<span class="keywordtype">void</span>)
<a name="l00430"></a>00430 {
<a name="l00431"></a>00431     <a class="code" href="group__ble__sdk__app__hrs__main.html#gaa752585d9b405d6e0c6fd392d7f64b59">s_battery_sim_cfg</a>.<a class="code" href="structble__sensorsim__cfg__t.html#a0de4531998c77245b8866f2ba909d0fa">min</a>          = <a class="code" href="group__ble__sdk__app__hrs__main.html#ga59eb06cba38be11278ebd2829e95bc26">MIN_BATTERY_LEVEL</a>;
<a name="l00432"></a>00432     <a class="code" href="group__ble__sdk__app__hrs__main.html#gaa752585d9b405d6e0c6fd392d7f64b59">s_battery_sim_cfg</a>.<a class="code" href="structble__sensorsim__cfg__t.html#a43e74ba18dc1a237d9f7737ce8df350e">max</a>          = <a class="code" href="group__ble__sdk__app__hrs__main.html#ga16896fb7a69ca90a4a4e341d5a888002">MAX_BATTERY_LEVEL</a>;
<a name="l00433"></a>00433     <a class="code" href="group__ble__sdk__app__hrs__main.html#gaa752585d9b405d6e0c6fd392d7f64b59">s_battery_sim_cfg</a>.<a class="code" href="structble__sensorsim__cfg__t.html#a4eed0a83fb9e9824223f835e2b7b3032">incr</a>         = <a class="code" href="group__ble__sdk__app__hrs__main.html#ga69eef02165834e4dabc5757b82dddbf1">BATTERY_LEVEL_INCREMENT</a>;
<a name="l00434"></a>00434     <a class="code" href="group__ble__sdk__app__hrs__main.html#gaa752585d9b405d6e0c6fd392d7f64b59">s_battery_sim_cfg</a>.<a class="code" href="structble__sensorsim__cfg__t.html#a91158ca4700058aaa6a54de96b67146a">start_at_max</a> = <span class="keyword">true</span>;
<a name="l00435"></a>00435     
<a name="l00436"></a>00436     <a class="code" href="group__ble__sdk__lib__sensorsim.html#ga87dbeaec725800b329897a89763da807" title="Initialize a triangular waveform sensor simulator.">ble_sensorsim_init</a>(&amp;<a class="code" href="group__ble__sdk__app__hrs__main.html#gaa51f5fc284e1b7e1570ab742fa9b63f3">s_battery_sim_state</a>, &amp;<a class="code" href="group__ble__sdk__app__hrs__main.html#gaa752585d9b405d6e0c6fd392d7f64b59">s_battery_sim_cfg</a>);
<a name="l00437"></a>00437     
<a name="l00438"></a>00438     <a class="code" href="group__ble__sdk__app__hrs__main.html#ga39e135ff0a64d6761269e856a46b8afe">s_heart_rate_sim_cfg</a>.<a class="code" href="structble__sensorsim__cfg__t.html#a0de4531998c77245b8866f2ba909d0fa">min</a>          = <a class="code" href="group__ble__sdk__app__hrs__main.html#ga8806d3ee13116211450e6fb3a2fb68a4">MIN_HEART_RATE</a>;
<a name="l00439"></a>00439     <a class="code" href="group__ble__sdk__app__hrs__main.html#ga39e135ff0a64d6761269e856a46b8afe">s_heart_rate_sim_cfg</a>.<a class="code" href="structble__sensorsim__cfg__t.html#a43e74ba18dc1a237d9f7737ce8df350e">max</a>          = <a class="code" href="group__ble__sdk__app__hrs__main.html#ga5c6a36078512a923ab07d1b8276c8cca">MAX_HEART_RATE</a>;
<a name="l00440"></a>00440     <a class="code" href="group__ble__sdk__app__hrs__main.html#ga39e135ff0a64d6761269e856a46b8afe">s_heart_rate_sim_cfg</a>.<a class="code" href="structble__sensorsim__cfg__t.html#a4eed0a83fb9e9824223f835e2b7b3032">incr</a>         = <a class="code" href="group__ble__sdk__app__hrs__main.html#ga509bd9abefc38f3b7f60c389132c9b81">HEART_RATE_INCREMENT</a>;
<a name="l00441"></a>00441     <a class="code" href="group__ble__sdk__app__hrs__main.html#ga39e135ff0a64d6761269e856a46b8afe">s_heart_rate_sim_cfg</a>.<a class="code" href="structble__sensorsim__cfg__t.html#a91158ca4700058aaa6a54de96b67146a">start_at_max</a> = <span class="keyword">false</span>;
<a name="l00442"></a>00442     
<a name="l00443"></a>00443     <a class="code" href="group__ble__sdk__lib__sensorsim.html#ga87dbeaec725800b329897a89763da807" title="Initialize a triangular waveform sensor simulator.">ble_sensorsim_init</a>(&amp;<a class="code" href="group__ble__sdk__app__hrs__main.html#ga267115c7f20ec331261551282d0ce0c1">s_heart_rate_sim_state</a>, &amp;<a class="code" href="group__ble__sdk__app__hrs__main.html#ga39e135ff0a64d6761269e856a46b8afe">s_heart_rate_sim_cfg</a>);
<a name="l00444"></a>00444     
<a name="l00445"></a>00445     <a class="code" href="group__ble__sdk__app__hrs__main.html#ga290a111981b0b7a7421cd249be9da006">s_rr_interval_sim_cfg</a>.<a class="code" href="structble__sensorsim__cfg__t.html#a0de4531998c77245b8866f2ba909d0fa">min</a>          = <a class="code" href="group__ble__sdk__app__hrs__main.html#gaeb7cf13d972734ca3c5e7b2ba037281e">MIN_RR_INTERVAL</a>;
<a name="l00446"></a>00446     <a class="code" href="group__ble__sdk__app__hrs__main.html#ga290a111981b0b7a7421cd249be9da006">s_rr_interval_sim_cfg</a>.<a class="code" href="structble__sensorsim__cfg__t.html#a43e74ba18dc1a237d9f7737ce8df350e">max</a>          = <a class="code" href="group__ble__sdk__app__hrs__main.html#ga11c7d3dc75939bf97dd4fcfce486f1de">MAX_RR_INTERVAL</a>;
<a name="l00447"></a>00447     <a class="code" href="group__ble__sdk__app__hrs__main.html#ga290a111981b0b7a7421cd249be9da006">s_rr_interval_sim_cfg</a>.<a class="code" href="structble__sensorsim__cfg__t.html#a4eed0a83fb9e9824223f835e2b7b3032">incr</a>         = <a class="code" href="group__ble__sdk__app__hrs__main.html#gaabc91ee3f6543ceae2371ce367323cac">RR_INTERVAL_INCREMENT</a>;
<a name="l00448"></a>00448     <a class="code" href="group__ble__sdk__app__hrs__main.html#ga290a111981b0b7a7421cd249be9da006">s_rr_interval_sim_cfg</a>.<a class="code" href="structble__sensorsim__cfg__t.html#a91158ca4700058aaa6a54de96b67146a">start_at_max</a> = <span class="keyword">false</span>;
<a name="l00449"></a>00449     
<a name="l00450"></a>00450     <a class="code" href="group__ble__sdk__lib__sensorsim.html#ga87dbeaec725800b329897a89763da807" title="Initialize a triangular waveform sensor simulator.">ble_sensorsim_init</a>(&amp;<a class="code" href="group__ble__sdk__app__hrs__main.html#gab8ed76f872599bde36873ea4702e752b">s_rr_interval_sim_state</a>, &amp;<a class="code" href="group__ble__sdk__app__hrs__main.html#ga290a111981b0b7a7421cd249be9da006">s_rr_interval_sim_cfg</a>);
<a name="l00451"></a>00451 }
<a name="l00452"></a>00452 
<a name="l00453"></a>00453 
<a name="l00456"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#ga9f11118fb9ce22ad1afe20af6f89b131">00456</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hrs__main.html#ga9f11118fb9ce22ad1afe20af6f89b131" title="Initialize security parameters.">sec_params_init</a>(<span class="keywordtype">void</span>)
<a name="l00457"></a>00457 {
<a name="l00458"></a>00458     <a class="code" href="group__ble__sdk__app__hrs__main.html#ga738ed84e141ba1059dd1318dc425343c">s_sec_params</a>.<a class="code" href="structble__gap__sec__params__t.html#a7f1ad43d3bf79b40bc39dbb5a6c3a5ae">timeout</a>      = <a class="code" href="group__ble__sdk__app__hrs__main.html#ga7c1fffb0f865552108560d4c63b32db1">SEC_PARAM_TIMEOUT</a>;
<a name="l00459"></a>00459     <a class="code" href="group__ble__sdk__app__hrs__main.html#ga738ed84e141ba1059dd1318dc425343c">s_sec_params</a>.<a class="code" href="structble__gap__sec__params__t.html#a3d9eee3a6a1d710b0e5d13b567675694">bond</a>         = <a class="code" href="group__ble__sdk__app__hrs__main.html#gacbf03a82593c273743a5a80a1119b851">SEC_PARAM_BOND</a>;
<a name="l00460"></a>00460     <a class="code" href="group__ble__sdk__app__hrs__main.html#ga738ed84e141ba1059dd1318dc425343c">s_sec_params</a>.<a class="code" href="structble__gap__sec__params__t.html#a808e5ec85cf1656a05a985386ba29276">mitm</a>         = <a class="code" href="group__ble__sdk__app__hrs__main.html#gab6831ebe113f8afe970326b7742b5947">SEC_PARAM_MITM</a>;
<a name="l00461"></a>00461     <a class="code" href="group__ble__sdk__app__hrs__main.html#ga738ed84e141ba1059dd1318dc425343c">s_sec_params</a>.<a class="code" href="structble__gap__sec__params__t.html#a81d248b843331e8798478feecf4f4c92">io_caps</a>      = <a class="code" href="group__ble__sdk__app__hrs__main.html#ga42df85b3a4083cdc614d9111d580d98f">SEC_PARAM_IO_CAPABILITIES</a>;
<a name="l00462"></a>00462     <a class="code" href="group__ble__sdk__app__hrs__main.html#ga738ed84e141ba1059dd1318dc425343c">s_sec_params</a>.<a class="code" href="structble__gap__sec__params__t.html#a01318f39f3b3471bd44bf2f322331788">oob</a>          = <a class="code" href="group__ble__sdk__app__hrs__main.html#gaee13a0d0077f423fa0edd74e17fb6b88">SEC_PARAM_OOB</a>;  
<a name="l00463"></a>00463     <a class="code" href="group__ble__sdk__app__hrs__main.html#ga738ed84e141ba1059dd1318dc425343c">s_sec_params</a>.<a class="code" href="structble__gap__sec__params__t.html#a66c3e526aae4ca7f3212ae207225b0a2">min_key_size</a> = <a class="code" href="group__ble__sdk__app__hrs__main.html#ga6b7b2e2f67fbf790f55b46f8f5e24ad5">SEC_PARAM_MIN_KEY_SIZE</a>;
<a name="l00464"></a>00464     <a class="code" href="group__ble__sdk__app__hrs__main.html#ga738ed84e141ba1059dd1318dc425343c">s_sec_params</a>.<a class="code" href="structble__gap__sec__params__t.html#a43d814618fbf7f63a318966dd84746c2">max_key_size</a> = <a class="code" href="group__ble__sdk__app__hrs__main.html#gaf2cd1595de153ea1d6d843619a1a7707">SEC_PARAM_MAX_KEY_SIZE</a>;
<a name="l00465"></a>00465 }
<a name="l00466"></a>00466 
<a name="l00467"></a>00467 
<a name="l00470"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#ga59f2752bdf059ab72ec3987d0b1db770">00470</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hrs__main.html#ga59f2752bdf059ab72ec3987d0b1db770" title="Start application timers.">application_timers_start</a>(<span class="keywordtype">void</span>)
<a name="l00471"></a>00471 {
<a name="l00472"></a>00472     uint32_t err_code;
<a name="l00473"></a>00473     
<a name="l00474"></a>00474     <span class="comment">// Start application timers</span>
<a name="l00475"></a>00475     err_code = <a class="code" href="group__app__timer.html#ga54651d3dc5266bd7541b80918527b060" title="Starts a timer.">app_timer_start</a>(APP_TIMER_BATTERY_LEVEL_MEAS, 
<a name="l00476"></a>00476                                <a class="code" href="group__ble__sdk__app__hrs__main.html#ga7e5b3d2cf024dde83b8c536b22a1c155" title="Battery measurement timer timeout handler.">battery_level_meas_timeout_handler</a>, 
<a name="l00477"></a>00477                                <a class="code" href="group__ble__sdk__app__hrs__main.html#gaf28f0232a3fdc0eb03b94eb34b25cde8">BATTERY_LEVEL_MEAS_INTERVAL</a>, 
<a name="l00478"></a>00478                                APP_TIMER_MODE_REPEATED, 
<a name="l00479"></a>00479                                <a class="code" href="group__app__timer.html#ga02ba0b12340bf53b472283b752257f06">APP_TIMER_LOWEST_PRI</a>);
<a name="l00480"></a>00480     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00481"></a>00481     {
<a name="l00482"></a>00482         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00483"></a>00483     }
<a name="l00484"></a>00484 
<a name="l00485"></a>00485     err_code = <a class="code" href="group__app__timer.html#ga54651d3dc5266bd7541b80918527b060" title="Starts a timer.">app_timer_start</a>(APP_TIMER_HEART_RATE_MEAS, 
<a name="l00486"></a>00486                                <a class="code" href="group__ble__sdk__app__hrs__main.html#ga5f2bc03dde9dbfbd8983fdf45085d55b" title="Heart rate measurement timer timeout handler.">heart_rate_meas_timeout_handler</a>, 
<a name="l00487"></a>00487                                <a class="code" href="group__ble__sdk__app__hrs__main.html#ga45a3c3dc5dec56bf2ed3d1c4fdb0ccdd">HEART_RATE_MEAS_INTERVAL</a>, 
<a name="l00488"></a>00488                                APP_TIMER_MODE_REPEATED, 
<a name="l00489"></a>00489                                <a class="code" href="group__app__timer.html#ga02ba0b12340bf53b472283b752257f06">APP_TIMER_LOWEST_PRI</a>);
<a name="l00490"></a>00490     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00491"></a>00491     {
<a name="l00492"></a>00492         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00493"></a>00493     }
<a name="l00494"></a>00494 
<a name="l00495"></a>00495     err_code = <a class="code" href="group__app__timer.html#ga54651d3dc5266bd7541b80918527b060" title="Starts a timer.">app_timer_start</a>(APP_TIMER_RR_INTERVAL, 
<a name="l00496"></a>00496                                <a class="code" href="group__ble__sdk__app__hrs__main.html#ga9cb0ab1ccfd2d0873091c3a76b7177af" title="RR interval timer timeout handler.">rr_interval_timeout_handler</a>, 
<a name="l00497"></a>00497                                <a class="code" href="group__ble__sdk__app__hrs__main.html#ga9de92171573c36ded6e571be86716129">RR_INTERVAL_INTERVAL</a>, 
<a name="l00498"></a>00498                                APP_TIMER_MODE_REPEATED, 
<a name="l00499"></a>00499                                <a class="code" href="group__app__timer.html#ga02ba0b12340bf53b472283b752257f06">APP_TIMER_LOWEST_PRI</a>);
<a name="l00500"></a>00500     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00501"></a>00501     {
<a name="l00502"></a>00502         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00503"></a>00503     }
<a name="l00504"></a>00504 
<a name="l00505"></a>00505     err_code = <a class="code" href="group__app__timer.html#ga54651d3dc5266bd7541b80918527b060" title="Starts a timer.">app_timer_start</a>(APP_TIMER_SENSOR_CONTACT_DETECTED, 
<a name="l00506"></a>00506                                <a class="code" href="group__ble__sdk__app__hrs__main.html#gac05c2186395218b520bdad865660f44d" title="Sensor Contact Detected timer timeout handler.">sensor_contact_detected_timeout_handler</a>, 
<a name="l00507"></a>00507                                <a class="code" href="group__ble__sdk__app__hrs__main.html#ga9922fc753e0f7eee90179b6d5f20f2c3">SENSOR_CONTACT_DETECTED_INTERVAL</a>, 
<a name="l00508"></a>00508                                APP_TIMER_MODE_REPEATED, 
<a name="l00509"></a>00509                                <a class="code" href="group__app__timer.html#ga02ba0b12340bf53b472283b752257f06">APP_TIMER_LOWEST_PRI</a>);
<a name="l00510"></a>00510     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00511"></a>00511     {
<a name="l00512"></a>00512         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00513"></a>00513     }
<a name="l00514"></a>00514 }
<a name="l00515"></a>00515 
<a name="l00516"></a>00516 
<a name="l00519"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#gadf80cd84ee702e57a2a416fe4f653eb8">00519</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hrs__main.html#gadf80cd84ee702e57a2a416fe4f653eb8" title="Start advertising.">advertising_start</a>(<span class="keywordtype">void</span>)
<a name="l00520"></a>00520 {
<a name="l00521"></a>00521     uint32_t err_code;
<a name="l00522"></a>00522     
<a name="l00523"></a>00523     err_code = <a class="code" href="group___b_l_e___g_a_p.html#gabdbf78c3a8b09c6f2fb92d8733096af8" title="Start advertising (GAP Discoverable, Connectable modes, Broadcast Procedure).">ble_gap_adv_start</a>(&amp;<a class="code" href="group__ble__sdk__app__hrs__main.html#ga50483ecf69a0ae87ce1a8a5e8fa73c04">s_adv_params</a>);
<a name="l00524"></a>00524     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00525"></a>00525     {
<a name="l00526"></a>00526         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00527"></a>00527     }
<a name="l00528"></a>00528     
<a name="l00529"></a>00529     <a class="code" href="group__nrf__gpio.html#gacaf7e8e242a47f7b635bbeca5c5934a3" title="Set GPIO pin.">nrf_gpio_pin_set</a>(ADVERTISING_LED_PIN_NO);
<a name="l00530"></a>00530 }
<a name="l00531"></a>00531 
<a name="l00532"></a>00532 
<a name="l00543"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#ga3518a4402961dbde9a52c7de6211ad7a">00543</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hrs__main.html#ga3518a4402961dbde9a52c7de6211ad7a" title="Connection Parameters Module handler.">on_conn_params_evt</a>(<a class="code" href="structble__conn__params__evt__t.html" title="Connection Parameters Module event.">ble_conn_params_evt_t</a> * p_evt)
<a name="l00544"></a>00544 {
<a name="l00545"></a>00545     uint32_t err_code;
<a name="l00546"></a>00546     
<a name="l00547"></a>00547     <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(p_evt-&gt;<a class="code" href="structble__conn__params__evt__t.html#a43fc16c6c20c00363c03e968c21c08d7">evt_type</a> == <a class="code" href="group__ble__sdk__lib__conn__params.html#ggae819a1b14dbebf447254ec41f644ec42a693314f30d0f73380ae2701d1094179a">BLE_CONN_PARAMS_EVT_FAILED</a>);
<a name="l00548"></a>00548     
<a name="l00549"></a>00549     err_code = <a class="code" href="group___b_l_e___g_a_p.html#ga1b72b0bedcc2ff560582527aee8e6416" title="Disconnect (GAP Link Termination).">ble_gap_disconnect</a>(<a class="code" href="group__ble__sdk__app__hrs__main.html#gaaf76d22968f9f320aa5005a25f654320">s_conn_handle</a>, BLE_HCI_CONN_INTERVAL_UNACCEPTABLE);
<a name="l00550"></a>00550     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00551"></a>00551     {
<a name="l00552"></a>00552         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00553"></a>00553     }
<a name="l00554"></a>00554 }
<a name="l00555"></a>00555 
<a name="l00556"></a>00556 
<a name="l00561"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#ga4538ed130db3bf7fc68b76a4d9e032fa">00561</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hrs__main.html#ga4538ed130db3bf7fc68b76a4d9e032fa" title="Connection Parameters module error handler.">conn_params_error_handler</a>(uint32_t nrf_error)
<a name="l00562"></a>00562 {
<a name="l00563"></a>00563     <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00564"></a>00564 }
<a name="l00565"></a>00565 
<a name="l00566"></a>00566 
<a name="l00569"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#gaf61b6c1c47f5c96b169ff81c345d7849">00569</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hrs__main.html#gaf61b6c1c47f5c96b169ff81c345d7849" title="Initialize the Connection Parameters module.">conn_params_init</a>(<span class="keywordtype">void</span>)
<a name="l00570"></a>00570 {
<a name="l00571"></a>00571     uint32_t               err_code;
<a name="l00572"></a>00572     <a class="code" href="structble__conn__params__init__t.html" title="Connection Parameters Module init structure. This contains all options and data needed for initializa...">ble_conn_params_init_t</a> cp_init;
<a name="l00573"></a>00573     
<a name="l00574"></a>00574     memset(&amp;cp_init, 0, <span class="keyword">sizeof</span>(cp_init));
<a name="l00575"></a>00575 
<a name="l00576"></a>00576     cp_init.<a class="code" href="structble__conn__params__init__t.html#ab211e40857ee8019c8fd5eabfcc12ce7">p_conn_params</a>                  = NULL;
<a name="l00577"></a>00577     cp_init.<a class="code" href="structble__conn__params__init__t.html#a915702f42f9a0316745403644d385f22">first_conn_params_update_delay</a> = <a class="code" href="group__ble__sdk__app__hrs__main.html#ga7204f7a367e8f1ac53ef62c4ad220efc">FIRST_CONN_PARAMS_UPDATE_DELAY</a>;
<a name="l00578"></a>00578     cp_init.<a class="code" href="structble__conn__params__init__t.html#a9bcd0621fbb5f4554f1fafd0b15dc61b">next_conn_params_update_delay</a>  = <a class="code" href="group__ble__sdk__app__hrs__main.html#gadf85796ef07632ed27e0bce9509d9245">NEXT_CONN_PARAMS_UPDATE_DELAY</a>;
<a name="l00579"></a>00579     cp_init.<a class="code" href="structble__conn__params__init__t.html#ab3c0944561623d4a8da622b18867aafb">max_conn_params_update_count</a>   = <a class="code" href="group__ble__sdk__app__hrs__main.html#ga34db81384bfbef23dedbef9bc6dfe46c">MAX_CONN_PARAMS_UPDATE_COUNT</a>;
<a name="l00580"></a>00580     cp_init.<a class="code" href="structble__conn__params__init__t.html#a6f0b0ef22161b61ba5cc0a7fd3ddedd9">start_on_notify_cccd_handle</a>    = <a class="code" href="group__ble__sdk__app__hrs__main.html#ga3e49fa0f1c47f72e98bc05de96dd24d4">s_hrs</a>.<a class="code" href="structble__hrs__s.html#af683c5e3e8c692ba6c20d8941483ce50">hrm_handles</a>.<a class="code" href="structble__gatts__char__handles__t.html#a2c7796d4eb58c25a1a724bcd9d5bf183">cccd_handle</a>;
<a name="l00581"></a>00581     cp_init.<a class="code" href="structble__conn__params__init__t.html#a7a3f3aac03305ef8012ade05399b5449">disconnect_on_fail</a>             = <span class="keyword">false</span>;
<a name="l00582"></a>00582     cp_init.<a class="code" href="structble__conn__params__init__t.html#af6344191be6d1f66ec79d6086def25f1">evt_handler</a>                    = <a class="code" href="group__ble__sdk__app__hrs__main.html#ga3518a4402961dbde9a52c7de6211ad7a" title="Connection Parameters Module handler.">on_conn_params_evt</a>;
<a name="l00583"></a>00583     cp_init.<a class="code" href="structble__conn__params__init__t.html#a893a7b5845beb42d9e5b650fd012f7f1">error_handler</a>                  = <a class="code" href="group__ble__sdk__app__hrs__main.html#ga4538ed130db3bf7fc68b76a4d9e032fa" title="Connection Parameters module error handler.">conn_params_error_handler</a>;
<a name="l00584"></a>00584     
<a name="l00585"></a>00585     err_code = <a class="code" href="group__ble__sdk__lib__conn__params.html#gacd9789a0a4c90cfea2ba2656f6408080" title="Initialize the Connection Parameters module.">ble_conn_params_init</a>(&amp;cp_init);
<a name="l00586"></a>00586     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00587"></a>00587     {
<a name="l00588"></a>00588         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00589"></a>00589     }
<a name="l00590"></a>00590 }
<a name="l00591"></a>00591 
<a name="l00592"></a>00592 
<a name="l00597"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#gad083cb3569230d7ecbf2d01ef2a2c1d9">00597</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hrs__main.html#gad083cb3569230d7ecbf2d01ef2a2c1d9" title="Application&#39;s BLE Stack event handler.">on_ble_evt</a>(<a class="code" href="structble__evt__t.html" title="Common BLE Event type, wrapping the module specific event reports.">ble_evt_t</a> * p_ble_evt)
<a name="l00598"></a>00598 {
<a name="l00599"></a>00599     uint32_t                         err_code = <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>;
<a name="l00600"></a>00600     <span class="keyword">static</span> <a class="code" href="structble__gap__evt__auth__status__t.html" title="Event data for authentication status event.">ble_gap_evt_auth_status_t</a> s_auth_status;
<a name="l00601"></a>00601     <a class="code" href="structble__gap__enc__info__t.html" title="GAP Encryption Information.">ble_gap_enc_info_t</a> *             p_enc_info;
<a name="l00602"></a>00602 
<a name="l00603"></a>00603     <span class="keywordflow">switch</span> (p_ble_evt-&gt;<a class="code" href="structble__evt__t.html#a50f33abba5627a26728ba30fffd9880a">header</a>.<a class="code" href="structble__evt__hdr__t.html#a826314e7ea25d4267621899efe6859f9">evt_id</a>)
<a name="l00604"></a>00604     {
<a name="l00605"></a>00605         <span class="keywordflow">case</span> <a class="code" href="group___b_l_e___g_a_p.html#ggabc5c98fcc1211af2b80116dd6e0a035daa0b4789724d202a13a5e7eab85c52957">BLE_GAP_EVT_CONNECTED</a>:
<a name="l00606"></a>00606             <a class="code" href="group__nrf__gpio.html#gacaf7e8e242a47f7b635bbeca5c5934a3" title="Set GPIO pin.">nrf_gpio_pin_set</a>(CONNECTED_LED_PIN_NO);
<a name="l00607"></a>00607             <a class="code" href="group__nrf__gpio.html#gaf3de3729249d55592c86ecfa97fb9347" title="Clear GPIO pin.">nrf_gpio_pin_clear</a>(ADVERTISING_LED_PIN_NO);
<a name="l00608"></a>00608             <a class="code" href="group__ble__sdk__app__hrs__main.html#gaaf76d22968f9f320aa5005a25f654320">s_conn_handle</a> = p_ble_evt-&gt;evt.<a class="code" href="structble__evt__t.html#a91857ca158f0c4e43f610068772c7d3d">gatts_evt</a>.<a class="code" href="structble__gatts__evt__t.html#a0d5ffe38d68e48d81e61fc6a4999ae68">conn_handle</a>;
<a name="l00609"></a>00609             <span class="keywordflow">break</span>;
<a name="l00610"></a>00610             
<a name="l00611"></a>00611         <span class="keywordflow">case</span> <a class="code" href="group___b_l_e___g_a_p.html#ggabc5c98fcc1211af2b80116dd6e0a035da057001bbd6ea9e615f19ef93cc0831ee">BLE_GAP_EVT_DISCONNECTED</a>:
<a name="l00612"></a>00612             <a class="code" href="group__nrf__gpio.html#gaf3de3729249d55592c86ecfa97fb9347" title="Clear GPIO pin.">nrf_gpio_pin_clear</a>(CONNECTED_LED_PIN_NO);
<a name="l00613"></a>00613             <a class="code" href="group__ble__sdk__app__hrs__main.html#gaaf76d22968f9f320aa5005a25f654320">s_conn_handle</a> = <a class="code" href="group___b_l_e___c_o_n_n___h_a_n_d_l_e_s.html#gacf227b9b101dbcf08eccbbaba54e48f5">BLE_CONN_HANDLE_INVALID</a>;
<a name="l00614"></a>00614             <a class="code" href="group__ble__sdk__app__hrs__main.html#gadf80cd84ee702e57a2a416fe4f653eb8" title="Start advertising.">advertising_start</a>();
<a name="l00615"></a>00615             <span class="keywordflow">break</span>;
<a name="l00616"></a>00616 
<a name="l00617"></a>00617         <span class="keywordflow">case</span> <a class="code" href="group___b_l_e___g_a_p.html#ggabc5c98fcc1211af2b80116dd6e0a035da6c5eefbcfabbc1ce4a8bcbf550c285ae">BLE_GAP_EVT_SEC_PARAMS_REQUEST</a>:
<a name="l00618"></a>00618             err_code = <a class="code" href="group___b_l_e___g_a_p.html#ga5339c2562371354a0e3752b86214b92a" title="Reply with GAP security parameters.">ble_gap_sec_params_reply</a>(<a class="code" href="group__ble__sdk__app__hrs__main.html#gaaf76d22968f9f320aa5005a25f654320">s_conn_handle</a>, 
<a name="l00619"></a>00619                                                 <a class="code" href="group___b_l_e___g_a_p___s_e_c___s_t_a_t_u_s.html#gaa0334dea24e449e5c28c88bbe8a1d00f">BLE_GAP_SEC_STATUS_SUCCESS</a>, 
<a name="l00620"></a>00620                                                 &amp;<a class="code" href="group__ble__sdk__app__hrs__main.html#ga738ed84e141ba1059dd1318dc425343c">s_sec_params</a>);
<a name="l00621"></a>00621             <span class="keywordflow">break</span>;
<a name="l00622"></a>00622             
<a name="l00623"></a>00623         <span class="keywordflow">case</span> <a class="code" href="group___b_l_e___g_a_p.html#ggabc5c98fcc1211af2b80116dd6e0a035da8958220152f7547da3b250b4f724877c">BLE_GAP_EVT_AUTH_STATUS</a>:
<a name="l00624"></a>00624             s_auth_status = p_ble_evt-&gt;evt.<a class="code" href="structble__evt__t.html#a2fd98f8868b9aea30d35bf71d41d646a">gap_evt</a>.params.<a class="code" href="structble__gap__evt__t.html#a350f0c3a127499fb3d522d361554e3eb">auth_status</a>;
<a name="l00625"></a>00625             <span class="keywordflow">break</span>;
<a name="l00626"></a>00626 
<a name="l00627"></a>00627         <span class="keywordflow">case</span> <a class="code" href="group___b_l_e___g_a_t_t_s.html#gga80155586fa275b28773c9b203f52cabaae3776204f11a583e105aed0e477601da">BLE_GATTS_EVT_SYS_ATTR_MISSING</a>:
<a name="l00628"></a>00628             err_code = <a class="code" href="group___b_l_e___g_a_t_t_s.html#ga65ae169e49530eb2fa4bf73053060a13" title="Update persistent system attribute info.">ble_gatts_sys_attr_set</a>(<a class="code" href="group__ble__sdk__app__hrs__main.html#gaaf76d22968f9f320aa5005a25f654320">s_conn_handle</a>, NULL, 0);
<a name="l00629"></a>00629             <span class="keywordflow">break</span>;
<a name="l00630"></a>00630 
<a name="l00631"></a>00631         <span class="keywordflow">case</span> <a class="code" href="group___b_l_e___g_a_p.html#ggabc5c98fcc1211af2b80116dd6e0a035daf1c60079f92820cb933ebdb66d2d8d7d">BLE_GAP_EVT_SEC_INFO_REQUEST</a>:
<a name="l00632"></a>00632             p_enc_info = &amp;s_auth_status.periph_keys.<a class="code" href="structble__gap__evt__auth__status__t_1_1periph__keys__t.html#a7eee7ec3b96cc86a0080ab368dae817d">enc_info</a>;
<a name="l00633"></a>00633             <span class="keywordflow">if</span> (p_enc_info-&gt;<a class="code" href="structble__gap__enc__info__t.html#aa1147a1ab6ff4c36934461ca71d73bef">div</a> == p_ble_evt-&gt;evt.<a class="code" href="structble__evt__t.html#a2fd98f8868b9aea30d35bf71d41d646a">gap_evt</a>.params.<a class="code" href="structble__gap__evt__t.html#a5f04f763d053c94297246b6ed351c66a">sec_info_request</a>.<a class="code" href="structble__gap__evt__sec__info__request__t.html#aa1147a1ab6ff4c36934461ca71d73bef">div</a>)
<a name="l00634"></a>00634             {
<a name="l00635"></a>00635                 err_code = <a class="code" href="group___b_l_e___g_a_p.html#ga31de499e23c1d7876612af2fa65f3c46" title="Reply with GAP security information.">ble_gap_sec_info_reply</a>(<a class="code" href="group__ble__sdk__app__hrs__main.html#gaaf76d22968f9f320aa5005a25f654320">s_conn_handle</a>, p_enc_info, NULL);
<a name="l00636"></a>00636             }
<a name="l00637"></a>00637             <span class="keywordflow">else</span>
<a name="l00638"></a>00638             {
<a name="l00639"></a>00639                 <span class="comment">// No keys found for this device</span>
<a name="l00640"></a>00640                 err_code = <a class="code" href="group___b_l_e___g_a_p.html#ga31de499e23c1d7876612af2fa65f3c46" title="Reply with GAP security information.">ble_gap_sec_info_reply</a>(<a class="code" href="group__ble__sdk__app__hrs__main.html#gaaf76d22968f9f320aa5005a25f654320">s_conn_handle</a>, NULL, NULL);
<a name="l00641"></a>00641             }
<a name="l00642"></a>00642             <span class="keywordflow">break</span>;
<a name="l00643"></a>00643 
<a name="l00644"></a>00644         <span class="keywordflow">case</span> <a class="code" href="group___b_l_e___g_a_p.html#ggabc5c98fcc1211af2b80116dd6e0a035da57e5d1061d9b3d1500fb3556a3fb8847">BLE_GAP_EVT_TIMEOUT</a>:
<a name="l00645"></a>00645             <span class="keywordflow">if</span> (p_ble_evt-&gt;evt.<a class="code" href="structble__evt__t.html#a2fd98f8868b9aea30d35bf71d41d646a">gap_evt</a>.params.<a class="code" href="structble__gap__evt__t.html#a17e289da592e731cde1451c2d5f3f24a">timeout</a>.<a class="code" href="structble__gap__evt__timeout__t.html#af5eca485cd2b34522478907d4c8f5bc6">src</a> == <a class="code" href="group___b_l_e___g_a_p___t_i_m_e_o_u_t___t_y_p_e_s.html#gafee7b7095fb21ed922c6719cc1c2d23f">BLE_GAP_TIMEOUT_TYPE_ADVERTISEMENT</a>)
<a name="l00646"></a>00646             { 
<a name="l00647"></a>00647                 <a class="code" href="group__nrf__gpio.html#gaf3de3729249d55592c86ecfa97fb9347" title="Clear GPIO pin.">nrf_gpio_pin_clear</a>(ADVERTISING_LED_PIN_NO);
<a name="l00648"></a>00648 
<a name="l00649"></a>00649                 <span class="comment">// Go to system-off mode (this function will not return; wakeup will cause a reset)</span>
<a name="l00650"></a>00650                 err_code = <a class="code" href="group__nrf__soc__api.html#ga302701614c7bb1c9fc01dafec2bb04fb" title="Puts the chip in System OFF mode.">nrf_power_system_off</a>();    
<a name="l00651"></a>00651             }
<a name="l00652"></a>00652             <span class="keywordflow">break</span>;
<a name="l00653"></a>00653             
<a name="l00654"></a>00654         <span class="keywordflow">default</span>:
<a name="l00655"></a>00655             <span class="keywordflow">break</span>;
<a name="l00656"></a>00656     }
<a name="l00657"></a>00657 
<a name="l00658"></a>00658     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00659"></a>00659     {
<a name="l00660"></a>00660         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00661"></a>00661     }
<a name="l00662"></a>00662 }
<a name="l00663"></a>00663 
<a name="l00664"></a>00664 
<a name="l00672"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#ga2b08d6ccb6e7f4588d2ac843d4494c0e">00672</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hrs__main.html#ga2b08d6ccb6e7f4588d2ac843d4494c0e" title="Dispatches a BLE stack event to all modules with a BLE stack event handler.">ble_evt_dispatch</a>(<a class="code" href="structble__evt__t.html" title="Common BLE Event type, wrapping the module specific event reports.">ble_evt_t</a> * p_ble_evt)
<a name="l00673"></a>00673 {
<a name="l00674"></a>00674     <a class="code" href="group__ble__sdk__srv__hrs.html#gac50e029608199cc8d52463acb3e8a02e" title="Heart Rate Service BLE stack event handler.">ble_hrs_on_ble_evt</a>(&amp;<a class="code" href="group__ble__sdk__app__hrs__main.html#ga3e49fa0f1c47f72e98bc05de96dd24d4">s_hrs</a>, p_ble_evt);
<a name="l00675"></a>00675     <a class="code" href="group__ble__sdk__srv__bas.html#ga01b70d77540660d7e312121d9f1d3b3a" title="Battery Service BLE stack event handler.">ble_bas_on_ble_evt</a>(&amp;<a class="code" href="group__ble__sdk__app__hrs__main.html#gab22f840926bbada5a0ba32f2f7dc94b3">s_bas</a>, p_ble_evt);
<a name="l00676"></a>00676     <a class="code" href="group__ble__sdk__lib__conn__params.html#gadef0873bee110db3da8b77f801177871" title="BLE stack event handler.">ble_conn_params_on_ble_evt</a>(p_ble_evt);
<a name="l00677"></a>00677     <a class="code" href="group__ble__sdk__app__hrs__main.html#gad083cb3569230d7ecbf2d01ef2a2c1d9" title="Application&#39;s BLE Stack event handler.">on_ble_evt</a>(p_ble_evt);
<a name="l00678"></a>00678 }
<a name="l00679"></a>00679 
<a name="l00680"></a>00680 
<a name="l00685"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#gaa06a7a39e83ec4cf3553f4ed6ba6323a">00685</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hrs__main.html#gaa06a7a39e83ec4cf3553f4ed6ba6323a" title="BLE stack initialization.">ble_stack_init</a>(<span class="keywordtype">void</span>)
<a name="l00686"></a>00686 {
<a name="l00687"></a>00687     uint32_t err_code = <a class="code" href="group__ble__stack__handler.html#gada9282a45a226bbe8544995b2fbf22dd" title="Initialize stack handler module.">ble_stack_handler_init</a>(<a class="code" href="group__nrf__sdm__api.html#ggaaf8fd5f0e57d456151c951e0f3715fc4a1c5e9917211a50eac336a3fd2e467756">NRF_CLOCK_LFCLKSRC_XTAL_20_PPM</a>, <a class="code" href="group__ble__sdk__app__hrs__main.html#ga2b08d6ccb6e7f4588d2ac843d4494c0e" title="Dispatches a BLE stack event to all modules with a BLE stack event handler.">ble_evt_dispatch</a>);
<a name="l00688"></a>00688     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00689"></a>00689     {
<a name="l00690"></a>00690         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00691"></a>00691     }
<a name="l00692"></a>00692 }
<a name="l00693"></a>00693 
<a name="l00694"></a>00694 
<a name="l00697"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#ga265c25c068555fbfae4ab4f391060040">00697</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__gzll__ui.html#gacef6dd444cb6560da652897ee43ab306" title="Initialize GPIOTE module for detecting buttons.">buttons_init</a>(<span class="keywordtype">void</span>)
<a name="l00698"></a>00698 {
<a name="l00699"></a>00699     <span class="comment">//set Button 0 as wakeup source</span>
<a name="l00700"></a>00700     <a class="code" href="group__ble__sdk__lib__util.html#ga6259b9f2ea4ab48312b1836c71f484bb" title="Macro to configure an I/O.">GPIO_PIN_CONFIG</a>(NRF6310_BUTTON_0, 
<a name="l00701"></a>00701                     GPIO_PIN_CNF_DIR_Input, 
<a name="l00702"></a>00702                     GPIO_PIN_CNF_PULL_Disabled, 
<a name="l00703"></a>00703                     GPIO_PIN_CNF_DRIVE_S0S1, 
<a name="l00704"></a>00704                     GPIO_PIN_CNF_SENSE_Low);
<a name="l00705"></a>00705 }    
<a name="l00706"></a>00706     
<a name="l00707"></a>00707     
<a name="l00710"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#ga3adda2642702fdb99b08992c39494000">00710</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hrs__main.html#ga3adda2642702fdb99b08992c39494000" title="Power manager.">power_manage</a>(<span class="keywordtype">void</span>)
<a name="l00711"></a>00711 {
<a name="l00712"></a>00712     uint32_t err_code = <a class="code" href="group__nrf__soc__api.html#ga2aae5f388f1b6179058c62e2fb05a547" title="Waits for an application event.">nrf_wait_for_app_event</a>();
<a name="l00713"></a>00713     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00714"></a>00714     {
<a name="l00715"></a>00715         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00716"></a>00716     }
<a name="l00717"></a>00717 }
<a name="l00718"></a>00718 
<a name="l00719"></a>00719 
<a name="l00722"></a><a class="code" href="group__ble__sdk__app__hrs__main.html#ga840291bc02cba5474a4cb46a9b9566fe">00722</a> <span class="keywordtype">int</span> <a class="code" href="group__ble__sdk__app__gzll__main.html#ga840291bc02cba5474a4cb46a9b9566fe" title="Application main function.">main</a>(<span class="keywordtype">void</span>)
<a name="l00723"></a>00723 {
<a name="l00724"></a>00724     <span class="comment">// Initialize</span>
<a name="l00725"></a>00725     <a class="code" href="group__ble__sdk__app__gzll__ui.html#ga67cfc3137a465e560792490e81365254" title="LEDs initialization.">leds_init</a>();
<a name="l00726"></a>00726     <a class="code" href="group__ble__sdk__app__gzll__ui.html#gacef6dd444cb6560da652897ee43ab306" title="Initialize GPIOTE module for detecting buttons.">buttons_init</a>();
<a name="l00727"></a>00727     <a class="code" href="group__ble__sdk__app__hrs__main.html#gaa06a7a39e83ec4cf3553f4ed6ba6323a" title="BLE stack initialization.">ble_stack_init</a>();
<a name="l00728"></a>00728     <a class="code" href="group__ble__sdk__app__hrs__main.html#ga09658aaa0774820d8f25249d551bc283" title="Timer initialization.">timers_init</a>();
<a name="l00729"></a>00729     <a class="code" href="group__ble__sdk__app__hrs__main.html#ga1004973353f351806e42896c491a5ab2" title="GAP initialization.">gap_params_init</a>();
<a name="l00730"></a>00730     <a class="code" href="group__ble__sdk__app__hrs__main.html#ga935c9624de0709fe228dbefa4b54de48" title="Advertising functionality initialization.">advertising_init</a>();
<a name="l00731"></a>00731     <a class="code" href="group__ble__sdk__app__hrs__main.html#ga5b27b40e18af00d43b92f57eaed0e9b2" title="Initialize services that will be used by the application.">services_init</a>();
<a name="l00732"></a>00732     <a class="code" href="group__ble__sdk__app__hrs__main.html#ga6f75e3fe8d4ed6400f9429987dee0f3e" title="Initialize the sensor simulators.">sensor_sim_init</a>();
<a name="l00733"></a>00733     <a class="code" href="group__ble__sdk__app__hrs__main.html#gaf61b6c1c47f5c96b169ff81c345d7849" title="Initialize the Connection Parameters module.">conn_params_init</a>();
<a name="l00734"></a>00734     <a class="code" href="group__ble__sdk__app__hrs__main.html#ga59f2752bdf059ab72ec3987d0b1db770" title="Start application timers.">application_timers_start</a>();
<a name="l00735"></a>00735     <a class="code" href="group__ble__sdk__app__hrs__main.html#ga9f11118fb9ce22ad1afe20af6f89b131" title="Initialize security parameters.">sec_params_init</a>();
<a name="l00736"></a>00736 
<a name="l00737"></a>00737     <a class="code" href="group__ble__sdk__app__hrs__main.html#gadf80cd84ee702e57a2a416fe4f653eb8" title="Start advertising.">advertising_start</a>();
<a name="l00738"></a>00738 
<a name="l00739"></a>00739     <span class="comment">// Enter main loop</span>
<a name="l00740"></a>00740     <span class="keywordflow">for</span> (;;)
<a name="l00741"></a>00741     {
<a name="l00742"></a>00742         <a class="code" href="group__ble__sdk__app__hrs__main.html#ga3adda2642702fdb99b08992c39494000" title="Power manager.">power_manage</a>();
<a name="l00743"></a>00743     }
<a name="l00744"></a>00744 }
<a name="l00745"></a>00745 
</pre></div></div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="nrf6310__nrf2752_2ble_2ble__app__hrs_2main_8c.html">main.c</a>      </li>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>


    <li class="footer">
      Copyright &copy 2006-2011 <a href="http://www.nordicsemi.no" style="text-decoration:none">Nordic Semiconductor</a>.
      All Rights Reserved.
      <a href="disclaimer.html">Disclaimer</a>
    </li>
   </ul>
 </div>


</body>
</html>
